package com.wushi.lenovo.asia5b.app_di.credit.presenter;

import com.mvp.base.BasePresenter;
import com.wushi.lenovo.asia5b.app_di.credit.mvpview.FpxFragmentView;
import com.wushi.lenovo.asia5b.app_http.ApiService;
import com.wushi.lenovo.asia5b.app_http.TopupService;
import com.wushi.lenovo.asia5b.app_model.credit.bean.ThirdTopupType;

import java.util.Map;

import javax.inject.Inject;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;


/**
 * Created by zhangyuncai on 2019/1/20.
 */
public class FpxFragmentPresenter extends BasePresenter<FpxFragmentView> {

    ApiService apiService;
    TopupService topupService;

    @Inject
    public FpxFragmentPresenter(ApiService apiService, TopupService topupService) {
        this.apiService = apiService;
        this.topupService = topupService;
    }

    public void getBanks2() {
//        baseSubscribe(apiService.getToBanks(UserInfo.getMemberId()), listResultModel -> {
//            getView().getBanks2Result(listResultModel);
//        });
        Disposable subscribe = topupService.getBanks()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnSubscribe(disposable -> {
                    getView().showLoadingBar(null);
                })
                .doAfterTerminate(() -> {
                    getView().dismissLoadingBar("");
                })
                .subscribe(resultModel -> {
                    getView().getbanks2Result(resultModel);
                }, throwable -> {
                    throwable.printStackTrace();
                });
        composite.add(subscribe);
    }

    public void validateTopup(Map<String, Object> map, ThirdTopupType thirdTopupType) {
        baseSubscribe(topupService.validateTopup(thirdTopupType.getValidateTopupPath(), map),
                resultModel -> {
                    getView().validateTopupResult(resultModel, map);
                });
    }
}